<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Using Zend_Currency - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.currency.usage.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.currency.usage.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.currency.introduction.html">Introduction to Zend_Currency</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.currency.html">Zend_Currency</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.currency.options.html">Options for currencies</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.currency.usage" class="section"><div class="info"><h1 class="title">Using Zend_Currency</h1></div>
    

    <div class="section" id="zend.currency.usage.generic"><div class="info"><h1 class="title">Generic usage</h1></div>
        

        <p class="para">
            The simplest usecase within an application is to use the clients locale. When you create
            a instance of <span class="classname">Zend_Currency</span> without giving any options, your
            clients locale will be used to set the proper currency.
        </p>

        <div class="example" id="zend.currency.usage.generic.example-1"><div class="info"><p><b>Example #1 Creating a currency with client settings</b></p></div>
            

            <div class="example-contents"><p>
                Let&#039;s assume that your client has set &quot;en_US&quot; as wished language within his browser.
                In this case <span class="classname">Zend_Currency</span> will automatically detect the
                currency which has to be used.
            </p></div>

            <pre class="programlisting brush: php">
$currency = new Zend_Currency();

// See the default settings which are depending on the client
// var_dump($currency);
</pre>


            <div class="example-contents"><p>
                The created object would now contain the currency &quot;US Dollar&quot; as this is the actual
                assigned currency for US (United States). It has also other options set, like
                &quot;$&quot; for the currency sign or &quot;USD&quot; for the abbreviation.
            </p></div>
        </div>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Automatic locale detection does not always work</b><br /></span>
            

            <p class="para">
                You should note that this automatic locale detection does not always work properly.
                The reason for this behaviour is that <span class="classname">Zend_Currency</span> must have
                a locale which includes a region. When the client would only set &quot;en&quot; as locale
                <span class="classname">Zend_Currency</span> would not know which of the more than 30
                countries was meant. In this case an exception would be raised.
            </p>

            <p class="para">
                A client could also omit the locale settings within his browser. This would lead to
                the problem that your environment settings will be used as fallback and could also
                lead to an exception.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.currency.usage.locale"><div class="info"><h1 class="title">Currency creation based on a locale</h1></div>
        

        <p class="para">
            To prevent the problems with your client you could simply set the wished locale
            manually.
        </p>

        <pre class="programlisting brush: php">
$currency = new Zend_Currency(&#039;en_US&#039;);

// You can also use the &#039;locale&#039; option
// $currency = new Zend_Currency(array(&#039;locale&#039; =&gt; &#039;en_US&#039;));

// See the actual settings which are fixed to &#039;en_US&#039;
// var_dump($currency);
</pre>


        <p class="para">
            As within our first example the used currency will be &quot;US Dollar&quot;. But now we are no
            longer dependend on the clients settings.
        </p>

        <p class="para">
            <span class="classname">Zend_Currency</span> also supports the usage of an application-wide
            locale. You can set a <span class="classname">Zend_Locale</span> instance in the registry as
            shown below. With this notation you can avoid setting the locale manually for each
            instance when you want to use the same locale throughout the application.
        </p>

        <pre class="programlisting brush: php">
// in your bootstrap file
$locale = new Zend_Locale(&#039;de_AT&#039;);
Zend_Registry::set(&#039;Zend_Locale&#039;, $locale);

// somewhere in your application
$currency = new Zend_Currency();
</pre>

    </div>

    <div class="section" id="zend.currency.usage.territory"><div class="info"><h1 class="title">Currency creation based on a country</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Currency</span> is also able to work on a given country by using
            <span class="classname">Zend_Locale</span> internally.
        </p>

        <pre class="programlisting brush: php">
$currency = new Zend_Currency(&#039;US&#039;);

// See the actual settings which are fixed to &#039;en_US&#039;
// var_dump($currency);
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Uppercase territories</b><br /></span>
            

            <p class="para">
                When you know that you are using a territory, then you should uppercase it.
                Otherwise you could get an in your eyes false locale in return. For example,
                when you give &quot;om&quot; then you could expect &quot;ar_OM&quot; to be returned. But in fact it
                returns &quot;om&quot;, as it&#039;s also a language.
            </p>

            <p class="para">
                Therefor always uppercase the input when you know that a territory is meant.
            </p>
        </p></blockquote>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.currency.introduction.html">Introduction to Zend_Currency</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.currency.html">Zend_Currency</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.currency.options.html">Options for currencies</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.currency.html">Zend_Currency</a></li>
  <li><a href="zend.currency.introduction.html">Introduction to Zend_Currency</a></li>
  <li class="active"><a href="zend.currency.usage.html">Using Zend_Currency</a></li>
  <li><a href="zend.currency.options.html">Options for currencies</a></li>
  <li><a href="zend.currency.description.html">What makes a currency?</a></li>
  <li><a href="zend.currency.position.html">Where is the currency?</a></li>
  <li><a href="zend.currency.number.html">How does the currency look like?</a></li>
  <li><a href="zend.currency.value.html">How much is my currency?</a></li>
  <li><a href="zend.currency.calculation.html">Calculating with currencies</a></li>
  <li><a href="zend.currency.exchange.html">Exchanging currencies</a></li>
  <li><a href="zend.currency.additional.html">Additional informations on Zend_Currency</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>